package com.ruoyi.pm.service.impl;

import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.pubfun.IdWorker;
import com.ruoyi.pm.domain.ExcPortUpdateCondition;
import com.ruoyi.pm.mapper.ExcPortUpdateConditionMapper;
import com.ruoyi.pm.service.IExcPortUpdateConditionService;
import com.ruoyi.framework.util.LoginUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 请求返回订单修改限制条件Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-04-12
 */
@Service
public class ExcPortUpdateConditionServiceImpl implements IExcPortUpdateConditionService 
{
    @Autowired
    private ExcPortUpdateConditionMapper excPortUpdateConditionMapper;

    @Autowired
    private RedisCache redisCache;

    final private static String prefix = "exc_port_update_condition:";

    /**
     * 查询请求返回订单修改限制条件
     * 
     * @param id 请求返回订单修改限制条件主键
     * @return 请求返回订单修改限制条件
     */
    @Override
    public ExcPortUpdateCondition selectExcPortUpdateConditionById(Long id)
    {
        return excPortUpdateConditionMapper.selectExcPortUpdateConditionById(id);
    }

    /**
     * 查询请求返回订单修改限制条件列表
     * 
     * @param excPortUpdateCondition 请求返回订单修改限制条件
     * @return 请求返回订单修改限制条件
     */
    @Override
    public List<ExcPortUpdateCondition> selectExcPortUpdateConditionList(ExcPortUpdateCondition excPortUpdateCondition)
    {
        return excPortUpdateConditionMapper.selectExcPortUpdateConditionList(excPortUpdateCondition);
    }

    /**
     * 新增请求返回订单修改限制条件
     * 
     * @param excPortUpdateCondition 请求返回订单修改限制条件
     * @return 结果
     */
    @Override
    public int insertExcPortUpdateCondition(ExcPortUpdateCondition excPortUpdateCondition)
    {
        //删缓存
        redisCache.deleteObject(prefix + excPortUpdateCondition.getPortId());
        excPortUpdateCondition.setId(IdWorker.getId());
        excPortUpdateCondition.setCreateBy(LoginUserUtil.getSysUser().getUserName());
        excPortUpdateCondition.setCreateTime(DateUtils.getNowDate());
        excPortUpdateCondition.setUpdateBy(LoginUserUtil.getSysUser().getUserName());
        excPortUpdateCondition.setUpdateTime(DateUtils.getNowDate());
        return excPortUpdateConditionMapper.insertExcPortUpdateCondition(excPortUpdateCondition);
    }

    /**
     * 修改请求返回订单修改限制条件
     * 
     * @param excPortUpdateCondition 请求返回订单修改限制条件
     * @return 结果
     */
    @Override
    public int updateExcPortUpdateCondition(ExcPortUpdateCondition excPortUpdateCondition)
    {
        //删缓存
        redisCache.deleteObject(prefix + excPortUpdateCondition.getPortId());
        excPortUpdateCondition.setUpdateBy(LoginUserUtil.getSysUser().getUserName());
        excPortUpdateCondition.setUpdateTime(DateUtils.getNowDate());
        return excPortUpdateConditionMapper.updateExcPortUpdateCondition(excPortUpdateCondition);
    }

    /**
     * 批量删除请求返回订单修改限制条件
     * 
     * @param ids 需要删除的请求返回订单修改限制条件主键
     * @return 结果
     */
    @Override
    public int deleteExcPortUpdateConditionByIds(Long[] ids)
    {

        ExcPortUpdateCondition excPortUpdateCondition = excPortUpdateConditionMapper.selectExcPortUpdateConditionById(ids[0]);
        //删缓存
        redisCache.deleteObject(prefix + excPortUpdateCondition.getPortId());
        return excPortUpdateConditionMapper.deleteExcPortUpdateConditionByIds(ids);
    }

    /**
     * 删除请求返回订单修改限制条件信息
     * 
     * @param id 请求返回订单修改限制条件主键
     * @return 结果
     */
    @Override
    public int deleteExcPortUpdateConditionById(Long id)
    {
        ExcPortUpdateCondition excPortUpdateCondition = excPortUpdateConditionMapper.selectExcPortUpdateConditionById(id);
        //删缓存
        redisCache.deleteObject(prefix + excPortUpdateCondition.getPortId());
        return excPortUpdateConditionMapper.deleteExcPortUpdateConditionById(id);
    }

    /**
     * 删除请求返回订单修改限制条件信息
     *
     * @param portId 接口Id
     * @return 结果
     */
    @Override
    public int deleteByPortId(Long portId){
        //删缓存
        redisCache.deleteObject(prefix + portId);
        return excPortUpdateConditionMapper.deleteByPortId(portId);
    }

    /**
     * 删除
     *
     * @param portConfigId 返回报文字段Id
     * @return 结果
     */
    @Override
    public int deleteByPortConfigId(Long portConfigId,Long portId){
        //删缓存
        redisCache.deleteObject(prefix + portId);
        return excPortUpdateConditionMapper.deleteByPortConfigId(portConfigId);
    }
}
